home *** CD-ROM | disk | FTP | other *** search
/ Compendium Deluxe 1 / LSD Compendium Deluxe 1.iso / a / programming / arexx / arexg10c.lha / ARexxGuide / Extras / ARexxGuide.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1993-07-28  |  4.7 KB  |  156 lines

  1. /* $VER: A.02 ARexxGuide.rexx (05.14.93) by Robin Evans
  2.  
  3.     This is still rough. It doesn't save the AG command to envarc: yet, for
  4.     one thing, but it should fix some of the previous problems (and create
  5.     a few new ones, I'm sure.
  6.  
  7.         Load xref files for ARexxGuide
  8. */
  9.     signal ON ERROR        /* AmigaGuide returns a '216' error code on some systems */
  10.     signal ON FAILURE
  11.  
  12.     call setclip('TextCodes', "csi='9b'x;slant=csi'3m';bold=csi'1m';norm=csi'0m';black=csi'31m';white=csi'32m';blue=csi'33m'")
  13.     XrefFile = 'ARx_Guide.xref'
  14.  
  15.     if ~show('L','amigaguide.library') then
  16.         call addlib('amigaguide.library',-2,-30,0)
  17.    if ~show('L','rexxsupport.library') then
  18.        call addlib('rexxsupport.library',0,-30,0)
  19.  
  20.           /* Function returns either 1 if rexxarplib is available or    **
  21.           ** 0 if it isn't. [Willy] can be used later as the condition  **
  22.           ** in IF statements.                                          */
  23.     Willy = CheckRxArp()        /* load rexxarplib if we have it */
  24.  
  25.     if loadxref(XrefFile) then    do
  26.         call pragma(s, 8192)
  27.             /* This won't work because ARexx commands cannot be executed **
  28.             ** from a AG window opened in this manner                    */
  29. /*        call shownode(,'ARexxGuide.guide', 'MAIN')  */
  30. /*        options failat 217 */
  31.         if ~show('P', ARX_GUIDE) then do
  32.             AGCmd = getenv('ARexxGuide/AGCmd')
  33.             if abbrev(AGCmd, 'Multi') then
  34.                 PrtOpt = ''
  35.             else
  36.                 PrtOpt = 'portname ARX_GUIDE'
  37.  
  38.                 /* we return a number if it's a bad name */
  39.             if datatype(AGCmd,'N') then do
  40.                 say 'Improper name for AmigaGuide utility:' AGCmd
  41.                 signal error
  42.             end
  43.             address command AGCmd 'ARexxGuide.guide' PrtOpt
  44.                 /* the AG library still seems to cause some incompatibility **
  45.                 ** with rexxarplib. Besides it's big. So this removes it.   */
  46.             call expungexref()
  47.             call remlib('amigaguide.library')
  48.         end
  49.         else do
  50.             address ARX_GUIDE
  51.             'windowtofront'
  52.             'ActivateWindow'
  53.                 /* don't know if this next one makes sense. It might be better **
  54.                 ** to just show the current document????                       */
  55.             /* 'link ArexxGuide.guide/MAIN' */
  56.         end
  57.     end
  58.     else do
  59.         interpret getclip('TextCodes')
  60.         say 'Couldn''t find xref file.'
  61.         say white'Please make sure the AmigaGuide path '
  62.         say 'variable is set (press HELP in AmigaGuide'
  63.         say 'for more info) and includes the path where'
  64.         say 'the "Arx_" files are located.'black
  65.     end
  66.  
  67. exit 0
  68.  
  69. ERROR:
  70. FAILURE:
  71.         call expungexref()
  72.         call remlib('amigaguide.library')
  73. exit
  74.  
  75.  
  76.     /* This uses rexxarplib's GETENV() if it's here */
  77. GetEnv: procedure    expose Willy
  78.  
  79.     AGCmd = ''
  80.     if Willy then
  81.         AGCmd = 'GetEnv'(arg(1))
  82.     else if open(.Env, 'env:'arg(1), R) then do
  83.         AGCmd = readln(.Env)
  84.         call close .Env
  85.     end
  86.  
  87.     if AGCmd = '' | ~exists(AGCmd) then
  88.         AGCmd = SetAGCmd(Willy)
  89.  
  90. return AGCmd
  91.  
  92. SetAGCmd: procedure
  93.  
  94.     arg Willy
  95.     InfoMsg = 'The program needs information about\the location of your AmigaGuide utility.\Please choose the program you use\to view AmigaGuide files.'
  96.     if Willy then do
  97.         call PostMsg(10,0,InfoMsg)
  98.         AGCmd = GetFile(10,55,,,"Choose AmigaGuide utility",,PATGAD,,356,145)
  99.         call PostMsg()
  100.     end
  101.     else do
  102.         call close STDOUT
  103.         if open(STDOUT, 'con:10/0/346/145/Choose AmigaGuide utility',W) then do
  104.             call close STDIN
  105.             call open(STDIN, '*', R)
  106.             /* pragma('*') is redundant on 2.0+ and WShell, but... */
  107.             call pragma('*', STDIN); call pragma('*', STDOUT)
  108.         end
  109.             /* if that didn't work we'll try for the best with the standard **
  110.             ** window defined in the icon (if that was used)                */
  111.         say translate(InfoMsg, '0a'x, '\')'0a'x
  112.         interpret getclip('TextCodes')
  113.         do forever    /* Break after checking for existence of file at end */
  114.             say blue'Please enter complete path of the'
  115.             say 'program. Enter program name as well.'black
  116.             options prompt black'Program?' white'::: 'black
  117.             parse pull AGCmd
  118.             if ~exists(AGCmd) | AGCmd = '' then do
  119.                 say AGCmd 'is not a valid file name'
  120.                 say blue'Try again?'
  121.                 options prompt white'(y/n) ::: 'black
  122.                 pull resp
  123.                 if abbrev(resp, 'Y') then iterate
  124.             end
  125.             break
  126.         end
  127.         call close STDOUT
  128.         call close STDIN
  129.         call pragma('*')        /* which doesn't work... grrrrr */
  130.     end
  131.  
  132.     if AGCmd > '' & exists(AGCmd) then do
  133.         call makedir('env:ARexxGuide')
  134.         if open(.EnvFile, 'env:ARexxGuide/AGCmd', W) then
  135.             call writech(.EnvFile, AGCmd)
  136.         call close .EnvFile
  137.     end
  138.     else return 10
  139.  
  140. return AGCmd
  141.  
  142. CheckRxArp: procedure
  143.  
  144.     signal on syntax    /* this will catch the unloaded library */
  145.     if ~show('L', 'rexxarplib.library') then do
  146.        call addlib('rexxarplib.library',0,-30,0)
  147.        call PostMsg()
  148.     end
  149. return 1        /* The syntax sub. will return 0 if it isn't available */
  150.  
  151. Syntax:
  152.     /* only CheckRxArp has this turned on, so being here means there   **
  153.    ** is no rexxarplib.library                                        */
  154.     call remlib('rexxarplib.library')
  155. return 0
  156.